package org.osomit.sacct.entity;

import org.json.simple.JSONObject;
import org.json.simple.JSONArray;

import java.util.List;

/**
 * @author Jian Fang (John.Jian.Fang@gmail.com)
 *
 * Date: Jun 30, 2009
 */
public class ApplicationAccountRecord extends Entity {
    private static final long serialVersionUID = 401605006486444647L;
    
    public final static String ENTITY_NAME = "ApplicationAccountRecord";

    public final static String CLIENT_ID = "clientId";
    private String clientId;

    public final static String ACCOUNTS = "accounts";
    private List<ApplicationAccount> accounts;

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public List<ApplicationAccount> getAccounts() {
        return accounts;
    }

    public void setAccounts(List<ApplicationAccount> accounts) {
        this.accounts = accounts;
    }

    public JSONObject toJSON() {
        JSONObject obj = new JSONObject();

        obj.put(CLIENT_ID, this.clientId);
        JSONArray arr = new JSONArray();
        if(accounts != null && accounts.size() > 0){
            for(ApplicationAccount account: accounts){
                arr.add(account.toJSON());
            }
        }

        obj.put(ACCOUNTS, arr);

        return obj;
    }
}
